#!/usr/bin/python   
#=00 Basic Pipeline
import pygst   
pygst.require("0.10")   
import gst   
   
class playback:   
    def __init__(self, filename):   
#=01 Create The Pipeline
        # Create the pipeline                                    #01
        self.pipeline = gst.Pipeline("pipeline")                 #01
#=02 Create The Source Element
        # Create the input                                       #02
        filesrc = gst.element_factory_make("filesrc", "input")   #02
#=03 Set the location
        filesrc.set_property('location', filename)                 #03
#=04 Converter
        # Create the converter                                     #04
        converter = gst.element_factory_make("mad", "converter")   #04
#=05 Sink
        # Create the output                                       #05
        output = gst.element_factory_make("alsasink", "output")   #05
        output.set_property('device', 'plughw:2')                     #05
#=06 Add to pipeline
        # Add them all to the pipeline   #06
        self.pipeline.add(filesrc)       #06
        self.pipeline.add(converter)     #06
        self.pipeline.add(output)        #06
#=07 Link Elements Together
        # Now link filesrc -> converter -> output   #07
        filesrc.link(converter)                     #07
        converter.link(output)                      #07
#=08 Start the pipeline
        # And start it running                       #08
        self.pipeline.set_state(gst.STATE_PLAYING)   #08

#=09 Python main function
if __name__ == "__main__":         #09
    import sys                     #09
    import gobject                 #09
    player=playback(sys.argv[1])   #09
#=10 Mainloop
    # We need a mainloop. Use the GLib one.    #10
    gobject.MainLoop().run()                   #10
